using System;
using System.IO;
using NMock2;


namespace NMockExtensions
{
    public class DelegateForMatcher : Matcher
    {
        private readonly object reciever;

        public DelegateForMatcher(object reciever)
        {
            this.reciever = reciever;
        }

        public override bool Matches(object o)
        {
            Delegate d = o as Delegate;

            bool doesMatch = (d != null);
            if (doesMatch)
            {
                doesMatch &= (d.Target == reciever);
            }

            return doesMatch;
        }

        public override void DescribeTo(TextWriter writer)
        {
            writer.Write("Delegate for '{0}'", reciever ?? "<NULL>");
        }
    }
}